home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_1 / 3d.gra < prev    next >
Text File  |  1995-03-23  |  7KB  |  349 lines

  1. Article 2250 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!dali.cs.montana.edu!milton!cmeyer
  3. From: cmeyer@milton.u.washington.edu (Colin Meyer)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Rotate 3d objects on HP48
  6. Message-ID: <10852@milton.u.washington.edu>
  7. Date: 9 Nov 90 01:39:29 GMT
  8. Distribution: comp.sys.handhelds
  9. Organization: University of Washington, Seattle
  10. Lines: 334
  11.  
  12. Rotate 3d V1 for HP48's.
  13.  
  14. Here is my nifty program for rotating three dimensional shapes.
  15. It even does perspectives, but no hidden line removal. Maybe on V2.
  16.  
  17. It is based on Three-Dimensional Graphics in Turbo Pascal, Computer 
  18. Language, Sept. 1990.
  19.  
  20. The Programs/Variables:
  21.  
  22.  SROTATE: start rotation.
  23.  SANIMATE: save grobs on stack (in FRAMES), start animation.
  24.  ANIMATE: start animation of previously saved grobs.
  25.  FRAMES: a list of grobs to animate.
  26.  OCTO: shape - an octohedron
  27.  CONE: shape - actually a six sided pyramid
  28.  CUBE: shape - cube!
  29.  
  30. (Don't worry about the rest of the programs, they're just my strange
  31.  attempt at modular programming!)
  32.  
  33. Shapes are specified by a list of two lists, a list of vertices (3d 
  34. vectors) and a list of lines between vertices:
  35.  
  36. { { [x1 y1 z1]
  37.     [x2 y2 z2]
  38.     ...
  39.     [xn yn zn] }
  40.   { v1 v2
  41.     v3 v4
  42.     ...
  43.     vn vn+1 } }
  44.  
  45. Each pair of vertices in the line list specifies one line. For instance, 
  46. { 1 2 } would be a list with only one line, between vertex 1 and vertex 2.
  47. { 1 2 2 3} would be a list with two lines, the first between vertices 1
  48. and 2, and the second between vertices 2 and 3.
  49.  
  50. To Use:
  51.  
  52. 1: shape (list of lists, as described about)
  53.  
  54. [SROTATE]
  55.  
  56. The Initial View is how the object is initially oriented.
  57. The object will be rotated on the third axis (the one not chosen for one 
  58. of the initial rotations).
  59. X axis = 1, Y axis = 2, Z = 3.
  60.  
  61. Distance views from: is in user units (try about the same as the width
  62. of the screen).
  63.  
  64. Rotation options: are as follows:
  65.  
  66. :Start\<): - the angle to start the rotation at.
  67. :End\<): - the angle to end the rotation at.
  68. :inc: - the increment of the angle between views.
  69.  
  70. (to do a complete circle, start at 0 degrees, end at 351 and do an 
  71.  increment of 9 - I've found 9 degrees is a small enough jump for smooth
  72.  animation.)
  73.  
  74. Rotate on new or 
  75. original axes?
  76.  
  77. -this refers to the initial view. Before that view is the original axes, 
  78.  during that view is the new axes. Confused? Just try both ways & you'll
  79.  understand.
  80.  
  81. Save as grobs for 
  82. later animation?
  83.  
  84. -self explanatory.
  85.  If you do choose to save grobs, You'll have to choose how big a grob to 
  86.  save. The program will draw the first frame, and prompt you for corners
  87.  of the grob to save. Move the cursor to each corner, and press [ENTER]
  88.  at each. Make sure to make the grob a bit bigger than the picture, 
  89.  because as it rotates, it may go out of close boundaries. After marking
  90.  corners, you must push [ATTN], then [ORANGE] [CONT].
  91.  
  92. The program will then go ahead and draw all the frames, saving them as 
  93. grobs on the stack if you chose so. 
  94.  
  95. When you end up with a bunch of grobs on the stack, Press [SANIMATE] to
  96. save them in the variable FRAMES and then animate them.
  97.  
  98. Whenever you already have grobs saved in FRAMES, just press [ANIMATE].     
  99.  
  100. To start, try a cube, and these options:
  101.  
  102. 1: (the cube)
  103.  
  104. [SROTATE]
  105.  
  106. :Axis1:1
  107. :\<)1:30 [ENTER]
  108.  
  109. :Axis2:2
  110. :\<)2:30 [ENTER] 
  111.  
  112. Distance viewed from:
  113.  
  114. 7 [ENTER]
  115.  
  116. Rotation options:
  117. :Start\<):0
  118. :End\<):351
  119. :inc:9 [ENTER]
  120.  
  121. Rotate on new or 
  122. original axes?
  123.  
  124. [ORIG]
  125.  
  126. Save as grobs for 
  127. later animation?
  128.  
  129. [NO]
  130.  
  131. (sit back and enjoy).
  132.  
  133.  
  134. -----CUT HERE-----
  135. %%HP: T(3)A(D)F(.);
  136. DIR
  137.   SROTATE
  138.     \<< 1 2 CF CF
  139. "Initial View:" DUP
  140. { ":Axis1:
  141. :\<)1:" {
  142. 1 8 } } INPUT SWAP
  143. { ":Axis2:
  144. :\<)2:" {
  145. 1 8 } } INPUT SWAP
  146. OBJ\-> DTAG SWAP DTAG
  147. DUP 3 ROLLD R3D ROT
  148. OBJ\-> DTAG SWAP DTAG
  149. DUP 3 ROLLD R3D
  150. SWAP 4 ROLL + 3
  151. ROLLD * SWAP NEG 6
  152. +
  153. "Distance viewed from:"
  154. "" INPUT OBJ\->
  155. "Rotation options:"
  156. {
  157. ":Start\<):
  158. :End\<):
  159. :inc:"
  160. { 1 9 } } INPUT
  161. OBJ\-> DTAG ROT DTAG
  162. ROT DTAG ROT 4 ROLL
  163. 5 ROLL 6 ROLL 7
  164. ROLL OBJ\-> DROP
  165. CLLCD
  166. "Rotate on new or 
  167. original axes?"
  168. 3 DISP { "NEW" ""
  169. "" "" "" "ORIG" }
  170. TMENU 0
  171.       DO DROP -1
  172. WAIT
  173.       UNTIL { 16.1
  174. 11.1 } SWAP POS DUP
  175. DUP
  176.         IF NOT
  177.         THEN 880 .1
  178. BEEP
  179.         END
  180.       END 0 MENU 1
  181. -
  182.       IF
  183.       THEN 1 SF
  184.       END CLLCD
  185. "Save as grobs for 
  186. later animation?"
  187. 3 DISP YN
  188.       IF
  189.       THEN 2 SF
  190.       END ROTATE 1 2
  191. CF CF
  192.     \>>
  193.   ANIMATE
  194.     \<< { # 0h # 0h }
  195. PVIEW
  196.       DO FRAMES OBJ\->
  197. 1 SWAP
  198.         START PICT
  199. { # 14h # Ah } ROT
  200. REPL
  201.         NEXT
  202.       UNTIL 0
  203.       END
  204.     \>>
  205.   SANIMATE
  206.     \<< DEPTH \->LIST
  207. 'FRAMES' STO ANIMATE
  208.     \>>
  209.   OCTO { {
  210. [ 0 1 1 ]
  211. [ 0 1 -1 ]
  212. [ 0 -1 -1 ]
  213. [ 0 -1 1 ]
  214. [ -1 0 0 ]
  215. [ 1 0 0 ]
  216. } { 1 2 2 3 3 4 4 1
  217. 5 1 5 2 5 3 5 4 6 1
  218. 6 2 6 3 6 4 } }
  219.   CONE { {
  220. [ 0 1 0 ]
  221. [ -.809 -1 .588 ]
  222. [ -.809 -1 -.588 ]
  223. [ .309 -1 -.951 ]
  224. [ 1 -1 0 ]
  225. [ .309 -1 .951 ]
  226. } { 1 2 1 3 1 4 1 5
  227. 1 6 2 6 2 3 3 4 4 5
  228. 5 6 } }
  229.   CUBE { {
  230. [ -1 1 1 ]
  231. [ 1 1 1 ]
  232. [ -1 -1 1 ]
  233. [ 1 -1 1 ]
  234. [ -1 1 -1 ]
  235. [ 1 1 -1 ]
  236. [ -1 -1 -1 ]
  237. [ 1 -1 -1 ]
  238. } { 1 2 2 4 4 3 3 1
  239. 5 6 6 8 8 7 7 5 1 5
  240. 2 6 4 8 3 7 } }
  241.   FRAMES 0
  242.   ROTATE
  243.     \<< \-> inc dst ax
  244. r pnts lines
  245.       \<<
  246.         IF 2 FS?
  247.         THEN ERASE
  248. OVER ax R3D r
  249.           IF 1 FS?
  250.           THEN SWAP
  251.           END *
  252. pnts SWAP dst NOBJ
  253. lines SKETCH PICT {
  254. # 3h # 0h }
  255. GROB 121 6 79EE60CE62DD81CD18B9B18B3039A3001B42A02AA6545045048AA209288AA0007F4E602A6EDD804D14B9A109209BA3001D42A02AAA54114504AAA20920A29000794EA0CEA2D5D0C508BAB10938929B0000000000000000000000000000000000
  256. REPL GRAPH HALT
  257.         ELSE 0 0
  258.         END \-> p1 p2
  259.         \<< ERASE {
  260. # 0h # 0h } PVIEW
  261.           FOR j j
  262. ax R3D r
  263.             IF 1
  264. FS?
  265.             THEN
  266. SWAP
  267.             END *
  268. pnts SWAP dst NOBJ
  269. lines ERASE SKETCH
  270.             IF 2
  271. FS?
  272.             THEN
  273. PICT p1 p2 SUB
  274.             END inc
  275.           STEP
  276.         \>>
  277.       \>>
  278.     \>>
  279.   R3D
  280.     \<<
  281. [[ 0 0 0 ]
  282.  [ 0 0 0 ]
  283.  [ 0 0 0 ]]
  284. OVER DUP 2 \->LIST 1
  285. PUT R\|v 3 MOD 1 +
  286. DUP 3 MOD 1 + ROT
  287. SIN LASTARG COS \->
  288. m1 m2 s c
  289.       \<< R\|^ m2 m2 2
  290. \->LIST c PUT m1 m1 2
  291. \->LIST c PUT m2 m1 2
  292. \->LIST s NEG PUT m1
  293. m2 2 \->LIST s PUT
  294.       \>>
  295.     \>>
  296.   NOBJ
  297.     \<< \-> r d
  298.       \<< { } R\|v OBJ\->
  299. 1 SWAP
  300.         START r d
  301. NVERT R\->C R\|^ + R\|v
  302.         NEXT R\|^
  303.       \>>
  304.     \>>
  305.   SKETCH
  306.     \<< SWAP 'PNTS'
  307. STO OBJ\-> 2 / 1 SWAP
  308.       START PNTS
  309. SWAP GET SWAP PNTS
  310. SWAP GET LINE
  311.       NEXT 'PNTS'
  312. PURGE
  313.     \>>
  314.   NVERT
  315.     \<< R\|v SWAP * V\->
  316. R\|^ DUP ROT + / DUP
  317. ROT * R\|v * R\|^
  318.     \>>
  319.   PPAR {
  320. (-4.09375,-2)
  321. (4.09375,2) X 0
  322. (0,0) FUNCTION Y }
  323.   YN
  324. \<< { "YES"
  325. GROB 21 8 000000000000000000000000000000000000000000000000
  326. GROB 21 8 000000000000000000000000000000000000000000000000
  327. GROB 21 8 000000000000000000000000000000000000000000000000
  328. GROB 21 8 000000000000000000000000000000000000000000000000
  329. "NO" } TMENU 0
  330.   DO DROP -1 WAIT
  331.   UNTIL { 16.1 11.1
  332. } SWAP POS DUP DUP
  333.     IF NOT
  334.     THEN 880 .1
  335. BEEP
  336.     END
  337.   END 0 MENU 1 -
  338. \>>
  339.   R\|v
  340. \<< DEPTH ROLLD
  341. \>>
  342.   R\|^
  343. \<< DEPTH ROLL
  344. \>>
  345. END
  346. -----END CUT-----
  347.  
  348.  
  349.